import React, { FC } from 'react'
import { TabBar } from 'antd-mobile'
import {
    useHistory,
    useLocation,
} from 'react-router-dom'
import {
    AppOutline,
    MessageOutline,
    UnorderedListOutline,
    UserOutline,
} from 'antd-mobile-icons'

const Bottom: FC = () => {
    const history = useHistory()
    const location = useLocation()
    const { pathname } = location

    const setRouteActive = (value: string) => {
        history.push(value)
    }

    const tabs = [
        {
            key: '/',
            title: '首页',
            icon: <AppOutline />,
        },
        {
            key: '/all',
            title: '全部',
            icon: <UnorderedListOutline />,
        },
        {
            key: '/news',
            title: '新闻',
            icon: <MessageOutline />,
        },
        {
            key: '/mine',
            title: '我的',
            icon: <UserOutline />,
        },
    ]

    return (
        <TabBar  activeKey={pathname} onChange={value => setRouteActive(value)}>
            {tabs.map(item => (
                <TabBar.Item key={item.key} icon={item.icon} title={item.title} />
            ))}
        </TabBar>
    )
}

export default Bottom